﻿using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using ProtoBuf.Message;
using NetWork;

namespace Room
{
    public class RoomNetRaid : RoomNetBase
    {
        public RoomRaid roomRaid {
            get { return roomBase as RoomRaid; }
        }

        public override void RegistSocketHandler()
        {
            base.RegistSocketHandler();
            NetAPI.RegistSocketHandler(OpDefine.SCWorldBossInfo, SCWorldBossInfo);
        }
        public override void UnRegistSocketHandler()
        {
            base.UnRegistSocketHandler();
            NetAPI.UnregisterSocketHandler(OpDefine.SCWorldBossInfo, SCWorldBossInfo);
        }

        public void SCWorldBossInfo(object obj) {
            var msg = obj as ProtoBuf.Message.SCWorldBossInfo;
            foreach (var info in msg.strongholdList) {
                var ch = roomRaid.charactorManager.GetCharactor(info.strongholdId);
                if (ch != null)
                {
                    RCLODRaidHold lod = ch.lod as RCLODRaidHold;
                    if (lod != null)
                    {
                        lod.SetData(info);
                        lod.Refresh();
                    }
                }
                else {
                    roomRaid.charactorManager.CreateRaidHold(info);
                    var _ch = roomRaid.charactorManager.GetCharactor(info.strongholdId);
                    if (_ch != null)
                    {
                        var lod = _ch.lod as RCLODRaidHold;
                        if (lod != null)
                        {
                            lod.Refresh();
                        }
                    }
                }
            }
        }

    }
}
